package test.redis;

import redis.clients.jedis.Jedis;

public class RedisClient implements MemcachedClient {
	 

	public RedisClient() {
		
	}

	@Override
	public String get(String key) {
		Jedis jedis = JedisUtil.getInstance().getJedis();
		String out = null;
		try {
			out = jedis.get(key);
		} catch (Exception e) {
			JedisUtil.getInstance().closeJedis(jedis);
		}
		finally{
			JedisUtil.getInstance().closeJedis(jedis);
		}
		return out;
	}

	@Override
	public boolean set(String key, String o, boolean longexist) {
		Jedis jedis = JedisUtil.getInstance().getJedis();
		try {
			jedis.set(key, o);
			if(!longexist)//文件
			{
				jedis.expire(key, 5*60);
			}
			else
			{
				//channel 永久有效,直到session过期.
			}
		} catch (Exception e) {
			JedisUtil.getInstance().closeJedis(jedis);
		}finally{
			JedisUtil.getInstance().closeJedis(jedis);
		}
		return true;
	}

	@Override
	public boolean delete(String key) {
		Jedis jedis = JedisUtil.getInstance().getJedis();
		try {
			jedis.del(key);
		} catch (Exception e) {
			JedisUtil.getInstance().closeJedis(jedis);
		}finally{
			JedisUtil.getInstance().closeJedis(jedis);
		}
		return true;
	}

	@Override
	public int size() {
		return 0;
	}

}
